/**
  ******************************************************************************
  * @file           : studio_plow_cover_ccpp.h
  * @author         : wangyingjie
  * @brief          : None
  * @attention      : None
  * @date           : 2025/6/8
  ******************************************************************************
  */

#ifndef STUDIO_PLOW_COVER_CCPP_H
#define STUDIO_PLOW_COVER_CCPP_H

#include "studio_macros.h"
#include <geometry/studio_geo.h>

class studio_plow_cover_ccpp
{
public:

    studio_plow_cover_ccpp(){}

    studio_plow_cover_ccpp(const studio_poly& poly, const double cell_m) : fence_poly(poly) , cell_size_m(cell_m)
    {
    }

    studio_plow_cover_ccpp(const std::map<int, std::vector<int>>& all_blocks)
        : all_blocks_(all_blocks)
    {
    }

    bool set_fence(const studio_poly& poly)
    {
        if (poly.outer_ring.points.empty())
        {
            std::cout << "studio_plow_cover_ccpp::set_fence: poly is empty!" << std::endl;
            return false;
        }
        fence_poly = poly;
        return true;
    }
    bool set_cell(const double cell_m)
    {
        cell_size_m = cell_m;
    }

    // 生成路径 (返回 <col, row> 对)
    studio_line generate_path();

private:
    studio_poly fence_poly;  // 围栏框
    studio_poly gs_fence_poly;
    double cell_size_m; // 栅格大小 (米)
    double central; // 围栏的中央经线
    std::map<int, std::vector<int>> all_blocks_;      // 所有覆盖块数据
    std::vector<std::pair<int, int>> base_path_;      // 基础路径 <col, row> base_path_，这是按行蛇形遍历生成的路径，不包含任何过渡点
    std::vector<std::pair<int, int>> optimized_path_; // 全覆盖路径块的顺序

    // 生成蛇形路径
    void generate_snake_path();

    // 添加行间过渡点
    void add_row_transitions();
};

#endif //STUDIO_PLOW_COVER_CCPP_H